﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace AsyncUnitTest
{
    public class MyTest7
    {
        public static void Go()
        {
            DemoAsync().Wait();
        }

        public static async Task DemoAsync()
        {
            Console.WriteLine($"Yield之前线程id:{Thread.CurrentThread.ManagedThreadId}");
            Task.Yield();
            Console.WriteLine($"Yield之后线程id:{Thread.CurrentThread.ManagedThreadId}");
            Thread.Sleep(3000);
        }

        public static async Task Demo2Async()
        {
            Console.WriteLine($"Yield之前线程id:{Thread.CurrentThread.ManagedThreadId}");
            await Task.Run(() => { }).ContinueWith(t =>
            {
                Console.WriteLine($"Yield之后线程id:{Thread.CurrentThread.ManagedThreadId}");
                Thread.Sleep(3000);
            });
        }
    }
}
